package cn.yanjr;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;

import cn.yanjr.mall.mall_base.service.SysDictService;
import cn.yanjr.mall.mall_base.service.impl.SysDictServiceImpl;

/**
 * Hello world!
 *
 */
public class App {

	private static final long BLOCK_TIME = 1000L * 60;

	public static void main(String[] args) {
		System.out.println("Hello World!");

		// 当前应用配置
		ApplicationConfig application = new ApplicationConfig();
		application.setName("wemall");

		// 连接注册中心配置
		RegistryConfig registry = new RegistryConfig();
		registry.setAddress("zookeeper://127.0.0.1:2182");// 注册中心地址

		// 服务提供者协议配置
		ProtocolConfig protocol = new ProtocolConfig();
		protocol.setName("dubbo");
		protocol.setPort(-1);
		protocol.setThreads(200);

		// 服务实现
		SysDictService sysDictService = new SysDictServiceImpl();
		// 注意：ServiceConfig为重对象，内部封装了与注册中心的连接，以及开启服务端口
		// 服务提供者暴露服务配置
		ServiceConfig<SysDictService> service = new ServiceConfig<SysDictService>();
		service.setApplication(application);
		service.setRegistry(registry);
		service.setProtocol(protocol);
		service.setInterface(SysDictService.class);
		service.setRef(sysDictService);
		service.setVersion("0.0.1");
		// 暴露及注册服务
		service.export();
		System.out.println("SysDictService 服务已暴露！");
		

		
		while (true) {
			try {
				Thread.sleep(BLOCK_TIME);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}

